package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.mapper.CourseTeacherMapper;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CourseTeacherServiceImpl implements CourseTeacherService {
    @Autowired
    private CourseTeacherMapper courseTeacherMapper;
    @Override
    public List<CourseTeacher> queryList(Long courseId) {
        LambdaQueryWrapper<CourseTeacher> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(CourseTeacher::getCourseId, courseId);
        return courseTeacherMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public CourseTeacher save(CourseTeacher courseTeacher) {
        if(courseTeacher.getId()==null){
            courseTeacherMapper.insert(courseTeacher);
        }else{
            courseTeacherMapper.updateById(courseTeacher);
        }
        return courseTeacherMapper.selectById(courseTeacher.getId());
    }

    @Override
    public void delete(Long courseId, Long teacherId) {
        LambdaQueryWrapper<CourseTeacher> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(CourseTeacher::getCourseId, courseId);
        lambdaQueryWrapper.eq(CourseTeacher::getId,teacherId);
        courseTeacherMapper.delete(lambdaQueryWrapper);
    }
}
